var PF = window.PF || {};
	PF.unixperms = {
       
	cache: {},
       
	init: function() {
		$('#perms-container input[type="checkbox"]').click(PF.unixperms.calcPerms);
		var permVal = document.getElementById('nodePerms').value;
		
		// there are 15 permission fields, 0 to 14
		var aInputs = document.getElementById('perms-container').getElementsByTagName('input');
		for (var i=0;i<15;i++) {
			
			if ((permVal >> i) & 1) {
				if (aInputs[i].type == 'checkbox') {
					aInputs[14-i].checked = true;
				}
			}
		}// for
	},
	hideEl: function(el) {
		if (el) {
			el.style.display = 'none';
		}
	},
	calcPerms: function(elForm){
		var aInputs = document.getElementById('perms-container').getElementsByTagName('input');
		var permVal = 0;

		for (var i=0, j=aInputs.length; i<j; i++){
			if (aInputs[i].type == 'checkbox' && aInputs[i].checked === true){
				permVal += parseInt(aInputs[i].value, 10);
			}
		}
           
		document.getElementById('nodePerms').value = permVal;
	}
	};

	PF.unixperms.init();
